package com.batchengine.manager;

import com.batchengine.pool.WorkerPool;
import static com.batchengine.pool.WorkerPoolFactory.createExecutorPool;
import com.batchengine.task.RecurringJob;
import static com.batchengine.task.TaskUtil.getRecurringJobMap;
import static com.batchengine.util.LoggingFactory.createLogger;
import org.apache.log4j.Logger;

import java.util.Map;

/**
 * Created by sunil.incubator@yahoo.com.
 * User: sunil.kalva
 * Date: Aug 13, 2009
 */
public class SystemWorkerManager extends WorkerManager {

    private static final Logger logger = createLogger();

    public SystemWorkerManager(String name) {
        super(name);
    }

    @Override
    protected void init() {

        logger.debug(String.format("calling user %s", name));

        Map<Long, RecurringJob> map = getRecurringJobMap();
        for (Long o : map.keySet()) {

            if (100 >= o) {
                continue;
            }

            RecurringJob job = map.get(o);
            WorkerPool pool = createExecutorPool(job.getMinWorkers(), job.getMaxWorkers(), job.getTaskInfo().getTaskId());
            pool.setName(String.format("System Pool::%s", job.getTaskInfo().getTaskId()));
            addWorkerPool(pool);
        }
    }
}
